// vim: ff=unix : foldmethod=marker : foldmarker=<<<,>>>
/*
 File: string.h
 Product: NOL Base
 Creating date: 06/01/2005 15:15
 Remark: 
*/
#ifndef lite_stringH
#define lite_stringH

#include <string.h>
#include <wchar.h>

#include "lite/define.h"
#include "lite/pointer.h"

typedef char c_t; //char
typedef c_t * c_p; typedef c_p * c_pp;
typedef const c_t * c_cp; 

typedef wchar_t w_t; //wide char (2 or 4 bytes)
typedef w_t * w_p; typedef w_p * w_pp;
typedef const w_t * w_cp; 

#define slen strlen
#define wlen wcslen

//pair type (datum) - i_t ptrSize; (c|v|i1)_p ptr;
#define STR__d(pair) (c_p)pair,(i_t)pair##Size
#define WSTR__d(pair) (w_p)pair,(i_t)pair##Size
#define RAW__d(pair) (v_p)pair,(i_t)pair##Size
#define DATA__d(pair) (i1_p)pair,(i_t)pair##Size

#define STRREF__d(pair) (c_pp)&pair,(i_p)&pair##Size
#define WSTRREF__d(pair) (w_pp)&pair,(i_p)&pair##Size
#define RAWREF__d(pair) (v_pp)&pair,(i_p)&pair##Size
#define DATAREF__d(pair) (i1_pp)&pair,(i_p)&pair##Size

#define FIX_STRING__d(nick) \
 do { if (nick##Size==-1) nick##Size=slen(nick); } while(0)
#define FIX_WSTRING__d(nick) \
 do { if (nick##Size==-1) nick##Size=wlen(nick); } while(0)

#define S_t(pair) c_p pair; i_t pair##Size
#define S_p(pair) c_p pair, i_t pair##Size
#define S_pp(pair) c_pp pair, i_p pair##Size

#define W_t(pair) w_p pair; i_t pair##Size
#define W_p(pair) w_p pair, i_t pair##Size
#define W_pp(pair) w_pp pair, i_p pair##Size

#define SLIT(s) "" s, (sizeof(s)/sizeof(c_t))-1
#define SLITZ(s) "" s, (sizeof(s)/sizeof(c_t))
#define WLIT(s) L"" s, (sizeof(s)/sizeof(w_t))-1
#define WLITZ(s) L"" s, (sizeof(s)/sizeof(w_t))

#define scmp strcmp
#define scmpn strncmp
#define wcmp wcscmp
#define wcmpn wcsncmp

inline_q c_p scpy(c_p src, c_p dst) 
 { i_t l=slen((char *)dst); mcpyi(src,dst,l+1); return src+l; };
#define scpyn strncpy

inline_q w_p wcpy(w_p src, w_p dst) 
 { i_t l=wcslen((wchar_t *)dst); mcpyi(src,dst,(l+1)*sizeof(wchar_t)); return src+l; };
#define wcpyn wcsncpy

#define __sbld__(exp) #exp
#define sbld(exp) __sbld__(exp)

inline_q w_p wdiln(w_p dst, c_p str, i_t size) { //dilute
 c_p sentinel=str+size;
 while (str<sentinel) *dst++=*str++;
 return dst;
 };

inline_q c_p sstin(c_p dst, w_p src, i_t size) { //stiffen
 w_p sentinel=src+size;
 while (src<sentinel) *dst++=(c_t)(*src++);
 return dst;
 };

/* FIXME
- to bulkee/text
 c_p ftos(f_t,c_p,i_t);
 f_t stof(c_p,c_pp);
 
 c_p itos(i_t,c_p,i_t);
 i_t stoi(c_p,c_pp);
 
 c_p itodec(i_t,c_p,i_t);
 c_p itohex(i_t,c_p,i_t);
 i_t dectoi(c_p,c_pp);
 i_t hextoi(c_p,c_pp);
*/

#endif
